package top.crossrun.webview.bridge.plugin.common;

import android.content.SharedPreferences;

import org.json.JSONObject;

import top.crossrun.webview.bridge.core.pls.BridgeCallBackFunction;
import top.crossrun.webview.bridge.core.pls.WebViewBridgePlugin;

/**
 * create by Run
 * on 2020/10/13 14:33
 * do
 */
public class SetSpference extends WebViewBridgePlugin {
    @Override
    public void handlerBridgeMsg(String msg, BridgeCallBackFunction callBackFunction) {
        try {
            JSONObject json = new JSONObject(new JSONObject(msg).getString("params"));
            String var1 = json.getString("key");
            String var3 = json.getString("value");
            SharedPreferences sp = getContext().getSharedPreferences(var1, 0);
            SharedPreferences.Editor editor = sp.edit();
            editor.putString(var1, var3);
            editor.apply();
            callBackFunction.onCallBackFunction("successful");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public String getPluginName() {
        return "setSpference";
    }
}
